package com.itheima.annotation;

import org.junit.Test;

import java.awt.print.Book;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;

@MyBook(value = "情深深雨蒙蒙",price = 99.9,authors = {"t","g"})
public class BookStore {
    @MyBook(value = "124",price = 8.9,authors = {"1","2"})
    public  void  test(){
        System.out.println("Test");
    }
}

class TestBookStore{
    @Test
    public void testMethod() throws NoSuchMethodException {
        //1.先得到类对象
        Class c = BookStore.class;
        //2. 找方法
        Method test = c.getDeclaredMethod("test");
        // 2. 判断类上是否存在注解
        if(test.isAnnotationPresent(MyBook.class)){
            MyBook Bookannotation =(MyBook) test.getDeclaredAnnotation(MyBook.class);
             System.out.println(Bookannotation.price());
             System.out.println(Bookannotation.value());
             System.out.println(Arrays.toString(Bookannotation.authors()));
        }

    }
}
